package summer.codegenerator.model.base;

import java.io.IOException;
import java.lang.reflect.Type;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

/**
 * 
 * 
 * @author 蒋振
 * @since 2019年6月26日 下午2:51:40
 */
public class EnumFastJSONSerializer implements ObjectSerializer {

	@Override
	public void write(JSONSerializer arg0, Object arg1, Object arg2, Type arg3, int arg4) throws IOException {
		Class<?> cls = (Class<?>) arg3;
		try {
			if (cls.isEnum() && EnumIndexable.class.isAssignableFrom(cls)) {
				EnumIndexable ei = (EnumIndexable) arg1;
				arg0.write(ei.getIndex());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
